#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#include <linux/kd.h>
#include <sys/ioctl.h>

void slam_alarm_handler(int a)
{
	int tty = open("/dev/console", 0), led;

	if(tty<3)
	{
		perror("open:");
		exit(0);
	}
	led = 0x07;
	if(ioctl(tty,KDSETLED,led)>0)
	      perror("ioctl led on:");
	sleep(1);
	led = 0xff;
	if(ioctl(tty,KDSETLED,led)>0)
	      perror("ioctl led off:");
	close(tty);
}

int main(void)
{
	/* The struct itimerval 
	 *   it_interval:means interval everytime after first time
	 *   it_value:means the first time interval
	 * The ITIMER_REAL timer come with SIGALRM signal
	 */
	struct itimerval t;
	t.it_interval.tv_usec = 0;
	t.it_interval.tv_sec = 2;
	t.it_value.tv_usec = 0;
	t.it_value.tv_sec = 2;
	if(setitimer(ITIMER_REAL, &t, NULL) < 0)
	{
		printf("Setitimer failed.\n");
		exit(-1);
	}
	signal(SIGALRM, slam_alarm_handler);

	while(1)
	{
		sleep(2);
	}

	exit(0);
}
